import java.util.Scanner;
public class OpenJudge26 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String input=sc.next();
        String[] stringArr=input.split(",");
        int left = stringArr[0].indexOf(stringArr[1]);
        int right = stringArr[0].lastIndexOf(stringArr[2]);
        if(left==-1||right==-1){
            System.out.println(-1);
        } else{
            if(right-left-stringArr[1].length()<-1){
                System.out.println(-1);
            }else{
                System.out.println(right-left-stringArr[1].length());
            }
        }
    }
}
